export default {
	namespaced: true,
	state: {
		userInfo: uni.getStorageSync('userInfo'),
	},
	mutations: {
		setUser(state, payload) {
			state.userInfo = payload
		},
	},
	actions: {
		async setUserAction(context) {
			const user = await uni.$hd.isLogin();
			if(user.user.avatar) {
				user.avatar = uni.$hd.baseUrl + '/common/file/' + user.user.avatar
			}
			uni.setStorageSync('userInfo', user)
			context.commit('setUser', user)
		},
		cleanUserAction(context) {
			context.commit('setUser', null)
			uni.removeStorageSync('userInfo')
		}
	},
}